package com.niknik.woody.utils;

import com.niknik.woody.utils.wunit.log.WLog;
import com.niknik.woody.utils.wunit.log.WLogger;

import java.text.MessageFormat;

public class Check {

  public static final String PARAM_MISSED_MSG = "Missed required parameter {0} was \"{1}\"";

  private static final WLogger log = WLog.get(Check.class);

  public static void argNotNull(Object value, String param) {
    if (null == value) {
      IllegalArgumentException ex = new IllegalArgumentException(MessageFormat.format(PARAM_MISSED_MSG, param, value));
      log.exThrow(ex);
      throw ex;
    }
  }

  public static void strNotEmpty(String value, String param) {
    if (null == value || value.length() == 0) {
      IllegalArgumentException ex = new IllegalArgumentException(MessageFormat.format(PARAM_MISSED_MSG, param, value));
      log.exThrow(ex);
      throw ex;
    }
  }

  public static void state(Boolean expr, String msg, String... params) {
    if (!expr) {
      IllegalStateException ex = new IllegalStateException(MessageFormat.format(msg, params));
      log.exThrow(ex);
      throw ex;
    }
  }
}
